home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok56.lha
/
TurboFiles_V2.0
/
(Turbo)Files.doc
next >
Wrap
Text File
|
1993-08-15
|
10KB
|
231 lines
DEFINITION (Turbo)Files V2.0;
CONST (* Modus for Open() *)
newFile = TRUE;
oldFile = FALSE;
CONST (* content of f.res *)
done = 0; (* all ok, no error *)
notdone = 1; (* unknown error *)
notOpen = 2; (* Open() has not opened the file or Close() closed it*)
openError = 3; (* error while opening the file *)
readError = 4; (* disk corrupt *)
writeError = 5; (* disk corrupt, disk full *)
seekError = 6; (* error by using SetPos() *)
endOfFile = 7; (* end of File *)
outOfMem = 8; (* not enough memory, buffer of Open() too big *)
notExists = 9; (* file to open not found *)
CONST (* Modes of SetPos() *)
beginning = Dos.beginning;
current = Dos.current;
end = Dos.end;
TYPE
File = RECORD
res : SHORTINT;
END;
PROCEDURE Open(VAR f: File; name: ARRAY OF CHAR;
bufferSize: LONGINT; new: BOOLEAN): BOOLEAN;
PROCEDURE ReadBytes (VAR f: File; adr: Exec.ADDRESS; len: LONGINT): LONGINT;
PROCEDURE WriteBytes(VAR f: File; adr: Exec.ADDRESS; len: LONGINT): BOOLEAN;
PROCEDURE ReadChar (VAR f: File; VAR ch: CHAR): BOOLEAN;
PROCEDURE WriteChar(VAR f: File; ch: CHAR): BOOLEAN;
PROCEDURE Read (VAR f: File; VAR block: ARRAY OF BYTE): BOOLEAN;
PROCEDURE Write(VAR f: File; block: ARRAY OF BYTE): BOOLEAN;
PROCEDURE ReadString (VAR f: File; VAR str: ARRAY OF CHAR): INTEGER;
PROCEDURE WriteString(VAR f: File; str: ARRAY OF CHAR): BOOLEAN;
PROCEDURE WriteLn(VAR f: File): BOOLEAN;
PROCEDURE Size(VAR f: File): LONGINT;
PROCEDURE GetPos(VAR f: File): LONGINT;
PROCEDURE SetPos(VAR f: File; offset: LONGINT; mode: LONGINT): BOOLEAN;
PROCEDURE Search(VAR f: File; str: ARRAY OF BYTE; len: INTEGER): LONGINT;
PROCEDURE Close(VAR f: File): BOOLEAN;
PROCEDURE Code(fileName, codeWord: ARRAY OF CHAR; decode: BOOLEAN):BOOLEAN;
PROCEDURE DeleteFile(name: ARRAY OF CHAR): BOOLEAN;
PROCEDURE Exists(name: ARRAY OF CHAR; VAR size: LONGINT): BOOLEAN;
This Module is a replacement for the Oberon module FileSystem. It simplifies
and accellerates the access to files. The modules Files and TurboFiles beha
ves in the same way, but TurboFiles is a little bit quicker because the im
portant procedures are written in Assembler. Files.mod is only for those
people who hate Assembler. All other should only use the Module TurboFiles.
Because TurboFiles has an assemblerpart, You have to Assemble the file
TurboFiles.asm (With A68k) and then You can use the CLI-command JOIN to jo
in TurboFiles.obj(s) and the assemblerpart TurboFiles.o:
JOIN TurboFiles.obj TurboFiles.o AS TF.obj
COPY TF.obj TO TurboFiles.obj
Now You can use TurboFiles.obj like an Oberon-Modul. TurboFiles uses no
static variables and respects the Amiga-Dos register-conventions, (only D0,
D1 A0 and A1 are changed by the Assembler-code) so You can make programs
which uses TurboFiles resident with ARP.Ares or Resident and start the
programs multiple times, if You have compiled it with the small-data option
If one of the following procedures returns the boolean value TRUE, then the
operation was successful and the field f.res has the value done. If an error
occurs, for example that You try to read over the end of the file, then the
used procedure will set f.res to a value unequal done and all following pro
cedure-calls (except Close()) will be ignored. In this case You can look at
f.res to find the reason for the error. f.res can have one of the following
values:
CONST (* content of f.res *)
done = 0; (* all ok, no error *)
notdone = 1; (* unknown error *)
notOpen = 2; (* Open() has not opened the file or Close() closed it*)
openError = 3; (* error while opening the file *)
readError = 4; (* disk corrupt *)
writeError = 5; (* disk corrupt, disk full *)
seekError = 6; (* error by using SetPos() *)
endOfFile = 7; (* end of File *)
outOfMem = 8; (* not enough memory, buffer of Open() too big *)
notExists = 9; (* file to open not found *)
PROCEDURE Open(VAR f: File; name: ARRAY OF CHAR;
bufferSize: LONGINT; new: BOOLEAN): BOOLEAN;
Before You can use one of the following procedures, You must open the file
with Open(). Open() opens the Dos-File and initializes the file-variable.
name is a Amiga-Dos filename like "Text" or "Pictures:pic23". buffersize
determines the size of the used buffer. One kByte should be enough, but when
You write to disk, a large buffer of 10 or more kByte is quicker. IF
new=TRUE, then a new file is created, otherwise Open() will try to open an
existing file.
The procedures to read from the file:
PROCEDURE Read(VAR f: File; VAR block: ARRAY OF BYTE): BOOLEAN;
Reads LEN(block) bytes from the file and stores it in block. block is
compatible to all datatypes, so this procedure can be used to read any
datas like Records, INTEGERS, ....
PROCEDURE ReadChar(VAR f: File; VAR ch: BYTE): BOOLEAN;
Reads one single character from the file.The same thing You can do by using
Read(), but TurboFiles.ReadChar() is much quicker than Read().
PROCEDURE ReadString(VAR f: File; VAR str: ARRAY OF CHAR): INTEGER;
Reads a string from the file using ReadChar(). The end of the string is
marked by 0X or linefeed (0AX). ReadString() will read not more than
LEN(str) characters. The result is the length of the string.
PROCEDURE ReadBytes(VAR f: File; adr: Exec.ADDRESS; len: LONGINT): LONGINT;
This is a low-level-procedure, because Exec.ADDRESS is used. You should
only use this procedure if You can't use the other read-procedures. adr is
the address to put the data to, and len determines how many bytes the
procedure should read. The result is the number bytes really readed. If no
error occurs, the result should be equal len. If You for example try to
read over the end of the file, the result will be less than len and f.res
is equal endOfFile.
The procedures to write data to a file:
PROCEDURE Write(VAR f: File; block: ARRAY OF BYTE): BOOLEAN;
Writes LEN(block) Bytes to the file. block is compatible with all
datatypes.
PROCEDURE WriteChar(VAR f: File; ch: BYTE): BOOLEAN;
Writes a single character to the file. Instead of WriteChar() You can use
Write(), but TurboFiles.WriteChar() is much faster.
PROCEDURE WriteString(VAR f: File; str: ARRAY OF CHAR): BOOLEAN;
Writes the string str to the file using WriteChar(). The string is not
terminated with a linefeed. If You will write the next string to a new
line, You must use WriteChar(f,ASCII.lf) OR WriteLn(f).
PROCEDURE WriteBytes(VAR f: File; adr: Exec.ADDRESS; len: LONGINT): BOOLEAN;
This is again a low-level-procedure. Use it only if You can't use the other
write-procedures. adr is the memory location from which WriteBytes() takes
the data, and len determines how many Bytes will be written to the file.
Now the procedures GetPos(), SetPos() and Size():
PROCEDURE GetPos(VAR f: File): LONGINT;
GetPos() gives You the current position in the file, measured from the
beginning of the file. If there was an error in a former operation and
f.res#done, then this procedure will return -1.
PROCEDURE SetPos(VAR f: File; offset: LONGINT; mode: LONGINT): BOOLEAN;
With this procedure You can jump to any position in the file. offset
determines the new position. If mode=beginning, then offset is the distance
from the beginning of the file. If mode=end, offset is the distance from
the end of the file. If mode=current, then we will move offset Bytes
forward (if offset>0) or backward (if offset<0). If You try to move to a
position out of the file, then f.res will get the value seekError.
PROCEDURE Size(VAR f: File): LONGINT;
Size() gives You the current size of the file in Bytes. If f.res#done, this
procedure will return -1.
PROCEDURE Search(VAR f: File; str: ARRAY OF BYTE; len: INTEGER): LONGINT;
This procedure searches for the string str, starting at the current
position. Only the first len Bytes of str are significant. If str is found,
then Search() set the position in the file to this location and returns
this position. If the search fails, -1 is returned and f.res # done.
PROCEDURE Close(VAR f: File): BOLEAN;
Closes an open file. You should use Close() to close an open file if You
don't want to work with it any more. When a program terminates without
closing all open Files, then this module closes all Dos-Files, but it saves
NOT the content of the buffer! If the file is allready closed ( because an
Open() was not succesfull, or because of an former call of Close(), this
Procedure will do nothing and only return FALSE. Although if f.res has the
value notOpen, then this Procedure returns without doing anything.
For the programer means this: If a file-variable is initialized by a call
of Open(), You can call Close() at any time without worrying about if the
file is open or not. There is one problem left. If Your program terminates
before You call Open(), and there is a CLOSE-statment in Your program which
calls Close(), it can hapen that Close() works on an uninitialized
file-variable. To avoid this, it is a save way to set f.res to notOpen at
the begin of Your program.
To use the following procedures, the file MUST be close!
PROCEDURE DeleteFile(name: ARRAY OF CHAR): BOOLEAN;
Deletes a file. The same as Dos.Delete().
PROCEDURE Exists(name: ARRAY OF CHAR; VAR size: LONGINT): BOOLEAN;
Exists() checks if or if not a file or directory exists. If a file or
directory called name exists, TRUE is returned. IF it is a file, size
contains the size of this file in bytes. If it is a directory, size is set
to -1.
PROCEDURE Code(fileName, codeWord: ARRAY OF CHAR; decode: BOOLEAN):BOOLEAN;
With this procedure You can code and decode any file. codeWord is a string
which can contain any character except 0X. If decode is true, Code()
decodes the file. The coded file has the same size and name as the original
file.
HINT: If any procedure fails, it will set f.res to a value different from
done. From this time on all following fileoperations are ignored. Normally
You should close the file in this case, but if the error is for example of
the type endOfFile, You can set f.res to done and go on working with this
file.
I tested this module on an A1000 with KS and WB 1.3, but is should work
on other Amiga's too!
Stefan Salewski, 09-Jun-1991